package com.wangjiacai.utils.configuration;

import com.wangjiacai.utils.ali.NettyNlsClient;
import com.wangjiacai.utils.ali.asr.AliAsrPool;
import com.wangjiacai.utils.ali.asr.SpeechTranscriber;
import com.wangjiacai.utils.ali.properties.AliProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({ AliProperties.class})
public class AliAsrConfiguration {

    @Bean
    @ConditionalOnMissingBean(NettyNlsClient.class)
    public NettyNlsClient nettyNlsClient(AliProperties aliProperties){
        return new NettyNlsClient(aliProperties.getAkID(),aliProperties.getAkSecret());
    }

    @Bean
    public AliAsrPool aliAsrPool(NettyNlsClient nettyNlsClient, AliProperties aliProperties){
        SpeechTranscriber speechTranscriber=new SpeechTranscriber(aliProperties.getAppKey());
        return new AliAsrPool(nettyNlsClient,speechTranscriber,aliProperties.getAsr().getMaxSize());
    }

}
